/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.module.background.controller;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseWebController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.EduValidateQuestion;
import com.xci.edu.core.filter.EduValidateQuestionFilter;
import com.xci.edu.core.service.EduValidateQuestionService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 学习验证问题页面控制器
 * @author 吕艳阳 lvyanyang@xci96716.com
 * @since 2020-11-24 10:19:12
 */
@Authorize
@Controller
@RequestMapping(value = "/background/eduValidateQuestion")
public class EduValidateQuestionController extends BaseWebController {
    /** 验证问题服务 */
    @Resource private EduValidateQuestionService eduValidateQuestionService;

    //region 页面

    /** 首页 */
    @GetMapping
    //@Authorize(code = "background.eduValidateQuestion")
    public String index() {
        return "background/eduValidateQuestion/index";
    }

    /** 新建页 */
    @GetMapping("/create")
    @Authorize(code = "background.eduValidateQuestion.insert")
    public String create(ModelMap map) {
        createMark(map);
        var entity = new EduValidateQuestion();
        entity.setId(XCI.nextId());
        // entity.setName();
        // entity.setOptionA();
        // entity.setOptionB();
        // entity.setOptionC();
        // entity.setOptionD();
        // entity.setAnswer();
        map.put("entity", entity);
        return "background/eduValidateQuestion/edit";
    }

    /** 编辑页 */
    @GetMapping("/edit")
    @Authorize(code = "background.eduValidateQuestion.update")
    public String edit(String id, ModelMap map) {
        var entity = eduValidateQuestionService.selectById(Long.valueOf(id));
        XCI.checkNotFoundData(entity, id);
        map.put("entity", entity);
        return "background/eduValidateQuestion/edit";
    }

    /** 详情页 */
    @GetMapping("/details")
    public String details(String id, ModelMap map) {
        var entity = eduValidateQuestionService.selectById(Long.valueOf(id));
        XCI.checkNotFoundData(entity, id);
        map.put("entity", entity);
        return "background/eduValidateQuestion/details";
    }

    //endregion

    //region 处理

    /** 表格查询 */
    @ResponseBody
    @PostMapping("/grid")
    @Authorize(code = "background.eduValidateQuestion.select")
    public BoolResult grid(EduValidateQuestionFilter filter) {
        return BoolResult.success(eduValidateQuestionService.selectPageList(filter));
    }

    /** 新建保存 */
    @ResponseBody
    @PostMapping("/createSave")
    @Authorize(code = "background.eduValidateQuestion.insert")
    public BoolResult createSave(@ModelAttribute EduValidateQuestion entity) {
        return eduValidateQuestionService.insert(entity);
    }

    /** 修改保存 */
    @ResponseBody
    @PostMapping("/updateSave")
    @Authorize(code = "background.eduValidateQuestion.update")
    public BoolResult updateSave(@ModelAttribute EduValidateQuestion entity) {
        return eduValidateQuestionService.update(entity);
    }

    /** 删除 */
    @ResponseBody
    @PostMapping("/delete")
    @Authorize(code = "background.eduValidateQuestion.delete")
    public BoolResult delete(String ids) {
        return eduValidateQuestionService.delete(ids);
    }

    /** 导出 */
    @GetMapping("/export")
    @Authorize(code = "background.eduValidateQuestion.export")
    public void export(EduValidateQuestionFilter filter) {
        XCI.exportExcel(eduValidateQuestionService.selectList(filter), EduValidateQuestion.class, "验证问题列表");
    }

    /** 验证窗体 */
    @GetMapping("/validate")
    @Authorize(code = "background.eduValidateQuestion.validate")
    public String validate( ModelMap map) {
        var entity = eduValidateQuestionService.randomValidate();
        map.put("entity", entity);
        return "background/eduValidateQuestion/validate";
    }

    /** 验证窗体加载数据 */
    @GetMapping("/validateData")
    @Authorize(code = "background.eduValidateQuestion.validate")
    public String validateData( ModelMap map) {
        var entity = eduValidateQuestionService.randomValidate();
        map.put("entity", entity);
        return "background/eduValidateQuestion/validate_data";
    }

    //endregion
}
